<?php
if ($_FILES["image"]["error"] > 0) {
    echo "错误: " . $_FILES["image"]["error"] . "<br>";
} else {
    // 设置上传目录，需要确保该目录存在且有写入权限
    $uploadDir = '../../uploads/';
    if (!is_dir($uploadDir)) {
        mkdir($uploadDir, 0777, true);
    }
    // Get the file extension
    $fileExtension = pathinfo($_FILES["image"]["name"], PATHINFO_EXTENSION);
    // Generate a file name in the format of year, month, day, hour, minute, and second
    $fileName = date('YmdHis') . '_' . uniqid() . '.' . $fileExtension;
    $uploadFile = $uploadDir . $fileName;

    if (move_uploaded_file($_FILES["image"]["tmp_name"], $uploadFile)) {
        // 返回图片的访问路径
        echo $uploadFile;
    } else {
        http_response_code(500);
        echo "文件上传失败";
    }
}
?>